

//
//  SinglePickerPageViewController.m
//  pickers选取器
//
//  Created by 小白 on 16/2/23.
//  Copyright © 2016年 小白. All rights reserved.
//

#import "SinglePickerPageViewController.h"

@interface SinglePickerPageViewController ()<UIPickerViewDataSource,UIPickerViewDelegate>

@property(nonatomic,strong)NSArray *list;


@end

@implementation SinglePickerPageViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.list = @[@"张1",@"张2",@"张3",@"张4",@"张5",@"张6",@"张7",@"张8",@"张9",@"张10"];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

- (IBAction)btnPr:(id)sender {
    //selectedRowInComponent:0 得到pickerview第几列选中了第几项
    int sel = [self.pickview selectedRowInComponent:0];//第0列选择了几项
    NSString *name = self.list[sel];//通过第几项
    UIAlertView *alert =  [[UIAlertView alloc]initWithTitle:@"选择了谁" message:name delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
    [alert show];
    
}
//有几列
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    return 1;
    
}
//第几列有几行
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    //当前就一列所以不需要判断component是哪一列 直接返回数组的数量作为行数
    return self.list.count;
}

//告诉pickview第几行是什么内容
-(nullable NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    return self.list[row];
}


//选择pickview内容时触发的事件
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    self.labelpickersingle.text = self.list[row];
}

































@end
